#include <QtCore>
#include "GitServer.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QStringList args = a.arguments();
    if (args.count() != 3 && args.count() != 4) {
        qDebug() << "command line like: " << endl
                 << "'GitServer <GitProjectsPath> <ListenPort> [zip-storage|oss-storage]'" << endl
                 << "e.g. 'GitServer D:/GitProjectsRoot 8080'";
        return 1;
    }
    int type = 0;
    if (args.count() == 4) {
        if (args.at(3) == "zip-storage") {
            type = 1;
        } else if (args.at(3) == "oss-storage") {
            type = 2;
        }
    }

    GitServer server;
    qDebug() << "start git server:" <<  server.startGitServer(args.at(1), args.at(2).toUInt(), type);
    qDebug().noquote() << "root path:" << QFileInfo(args.at(1)).absoluteFilePath() << " port:" << args.at(2);
    qDebug() << "to init git project:  1. 'git init --bare'  2. 'git update-server-info'";
    qDebug().noquote() << ("to access git proejct: http://127.0.0.1:" + args.at(2) + "/" + QDir(args.at(1)).dirName() + "/xxxx.git")
             << ("or http://127.0.0.1:" + args.at(2) + "/" + QDir(args.at(1)).dirName());

    return a.exec();
}
